import { http } from '../../utils/net.js'
Page({
  data: {
    cardInfo:null
  },
  onLoad: function (options) {
    let that = this
    const eventChannel = this.getOpenerEventChannel()
    // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('acceptDataFromOpenerPage', function (data) {
      console.log(data)
      that.setData({
        cardInfo: data.cardInfo
      })
    })
  },
  toDelete() {
    wx.showModal({
      content: '确认删除此卡',
      success: (res) => {
        if(res.confirm) {
          http({
            url: "/api/index/index?method=del_credit",
            data: {
              bc_id: this.data.cardInfo.bc_id
            },
            isShowLoading: true,
            successCb: (res) => {
              wx.showToast({
                title: res.msg,
                icon: "success"
              })
              setTimeout(() => {
                wx.navigateBack({
                  delta: 1
                })
              }, 500)
            }
          })
        }
      }
    })
  }
})